# coding=utf-8
import urllib2
import re
page = 1
url = 'https://www.qiushibaike.com/hot/page/' + str(page)
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
try:
    request = urllib2.Request(url,headers=headers)
    response = urllib2.urlopen(request).read().decode('utf-8')
    patternStr ='<div class="article.*?<h2>(.*?)</h2>'\
     '.*?<a href="(.*?)"'\
     '.*?<span>(.*?)</span>'\
     '.*?<!-- 图片或gif -->(.*?)<div class="stats">'.decode('utf-8')\
     # '.*?<span class="stats-vote"><i class="number">(.*?)</i>'
    pattern = re.compile(patternStr, re.S)
    print response
    print '---------------------------------------------------'
    items = re.findall(pattern,response)
    print '++++++++++++++++++++++++++++++++++++++++++++++++++++'
    for item in items:
        # if not re.search('img',item[3]):
        print item[0]+item[1]+item[2]+item[3]
              #+item[4]


except urllib2.URLError,e:
    if hasattr(e, "code"):
        print e.code
    if hasattr(e, "reason"):
        print e.reason